package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppBiaoqian;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 个性标签
 * @author anxiang
 */
@Repository
public class AfterBiaoqianDao extends BaseDao<AppBiaoqian> {

    /**
     * 查询列表
     */
    public List<AppBiaoqian> list(Map<String, Object> paraMap, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_biaoqian where 1=1");
        if (StringEx.isNotNull(paraMap.get("leixing"))) {
            sbStr.append(" and leixing = ? ");
            paramList.add(paraMap.get("leixing"));
        }
        if (StringEx.isNotNull(paraMap.get("name"))) {
            sbStr.append(" and name = ? ");
            paramList.add(paraMap.get("name"));
        }
        if (StringEx.isNotNull(paraMap.get("country"))) {
            sbStr.append(" and country = ? ");
            paramList.add(paraMap.get("country"));
        }
        sbStr.append(" order by createtime desc");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppBiaoqian.class, splitPage);
    }

    /**
     * 详情
     */
    public AppBiaoqian get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_biaoqian where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppBiaoqian.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppBiaoqian pojo) {
        if (pojo.getId() != null && pojo.getId() > 0) {
            this.update(pojo);
        } else {
            pojo.setId(this.add(pojo));
        }
    }

    public void delete(Integer id) {
        if (id == null || id<=0) {
            return;
        }
        ArrayList<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("delete from app_biaoqian where id = ?");
        list.add(id);
        String sql = str.toString();
        this.del(sql, list);
    }
}
